SetGfxDriver 1:Graphics 1024,768,8,2:SeedRnd MilliSecs() :SetBuffer FrontBuffer()
Global sort1
Dim decode(10000):Dim encode(10000):Dim aaa(60):sort1 = CreateBank(60)
Type ants 
 Field x1,x2,x3,x4,x5,x6,x7,x8,x9,z1,z2,z3,z4,z5,z6,z7,z8,z9,d1,d2
End Type
decodet()
	For i=1 To 9
	ant.ants = New ants
	ant\x1=Rand(0,255):ant\x2=Rand(0,255):ant\x3=Rand(0,255):ant\x4=Rand(0,255):ant\x5=Rand(0,255):ant\x6=Rand(0,255):ant\x7=Rand(0,255):ant\x8=Rand(0,255):ant\x9=Rand(0,255)
	ant\z1=ant\x1:ant\z2=ant\x2:ant\z3=ant\x3:ant\z4=ant\x4:ant\z5=ant\x5:ant\z6=ant\x6:ant\z7=ant\x7:ant\z8=ant\x8:ant\z9=ant\x9
	ant\d1=""+fact(ant\z1,ant\z2,ant\z3)+""+fact(ant\z4,ant\z5,ant\z6)+""+fact(ant\z7,ant\z8,ant\z9)
	ant\d2=fact(fact(ant\z1,ant\z2,ant\z3),fact(ant\z4,ant\z5,ant\z6),fact(ant\z7,ant\z8,ant\z9))
	Next
While Not KeyHit(1) 
ClsColor 0,0,0
Cls
randants()
drawants(20,20)



Flip
If zzz1> 9 Then  WaitMouse() 
zzz1=zzz1+1
VWait 
Wend 

Function randants()
		For ant.ants=Each ants
		ant\x1=Rand(0,255):ant\x2=Rand(0,255):ant\x3=Rand(0,255):ant\x4=Rand(0,255):ant\x5=Rand(0,255):ant\x6=Rand(0,255):ant\x7=Rand(0,255):ant\x8=Rand(0,255):ant\x9=Rand(0,255)
		ant\z1=ant\x1:ant\z2=ant\x2:ant\z3=ant\x3:ant\z4=ant\x4:ant\z5=ant\x5:ant\z6=ant\x6:ant\z7=ant\x7:ant\z8=ant\x8:ant\z9=ant\x9
		ant\d1=""+fact(ant\z1,ant\z2,ant\z3)+""+fact(ant\z4,ant\z5,ant\z6)+""+fact(ant\z7,ant\z8,ant\z9)
		ant\d2=fact(fact(ant\z1,ant\z2,ant\z3),fact(ant\z4,ant\z5,ant\z6),fact(ant\z7,ant\z8,ant\z9))
		Next
End Function

Function drawants(x1,y1)
		x=x1:y=y1
		For ant.ants=Each ants
			Color 255,255,255
			Text x,y,ant\z1,False,False:y=y+9
			Text x,y,ant\z2,False,False:y=y+9
			Text x,y,ant\z3,False,False:y=y+9
			Text x,y,ant\z4,False,False:y=y+9
			Text x,y,ant\z5,False,False:y=y+9
			Text x,y,ant\z6,False,False:y=y+9
			Text x,y,ant\z7,False,False:y=y+9
			Text x,y,ant\z8,False,False:y=y+9
			Text x,y,ant\z9,False,False:y=y+9
			Color 255,255,0:y=y+9:Text x,y,ant\d1,False,False
			Color 255,255,0:y=y+9:Text x,y,ant\d2,False,False:y=y+9			
			x=x+18:y=y1
		Next
End Function

Function fact(x1,x2,x3)
        aaa(0)=x1+1:aaa(1)=x2+1:aaa(2)=x3+1
	For x=3 To 1 Step -1
	maxx =0
	For xt=0 To 2
	xx = aaa(xt):If maxx<xx Then maxx=xx:yy2=xt
	Next 
	aaa(yy2) =-10:PokeByte sort1,yy2,x
	Next
	ttt = Int(""+ PeekByte (sort1,0) +""+PeekByte (sort1,1) +""+PeekByte (sort1,2))
	xx = encode(ttt)
	Return xx
End Function

Function decodet()
y=0
For x1=1 To 3
For x2=1 To 3
For x3=1 To 3
If((x1 <> x2) And (x1<>x3) And (x2<>x3)) decode(y) =x1+""+x2+""+x3:encode(Int(""+x1+""+x2+""+x3))=y:y=y+1
Next
Next
Next
End Function

